<section class="general-wrapper company">
<section class="company-names">
<?php renderAdForm('left-1');?>

<?php 
$page_url = 'http://stoneselector.com/quarries/';
$filterBy = isset($_GET['f']) ? trim($_GET['f']) : 'a';

$alpha=array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
?>
<ul class="alpha-bets">
<?php
foreach($alpha as $a):
	$selected = ($filterBy == $a) ? 'class="selected"' : '';
	echo '<li '.$selected.'><a href="'.$page_url.'?f='.$a.'">'.$a.'</a></li>';
		
endforeach;
?>
</ul>
</section>
</section>

<section class="general-wrapper product">
<?php
global $wpdb;

$posts_ids = $wpdb->get_results( "SELECT ID FROM wp_posts
					  			   where post_title LIKE '$filterBy%'");
									   
$ids_list = array();									   
foreach($posts_ids as $id)
{
	$ids_list[] = $id -> ID;
}

//print_r($ids_list);
$args = array(  'cat'				=> 32,		// hooked by Quarries category
				'posts_per_page'	=> -1,
				'post__in'			=> $ids_list,
				'orderby'			=> 'title',
				'order'				=> 'ASC'
				);			   
								   
		$posts = query_posts($args);
		?>
        
        <ul class="company-listings">
<?php while (have_posts() ) : the_post();?>
	<li>
    	<section class="company-logo">
            <?php if ( has_post_thumbnail() ): 
					the_post_thumbnail('company-logo');
				else:
				?>
             <img src="<?php bloginfo('template_directory')?>/images/noLogo.png" alt="<?php the_title()?>" />
             <?php endif;?>
    	</section>
        <section class="company-detail">
        	<!--Premium Listings-->
            <div class="title"><?php the_title()?></div>
            <p><?php the_excerpt()?></p>
        </section>
        <section class="company-contact">
        	<!--Creastone Limited-->
            <a href="<?php the_permalink()?>"><input type="button" value="Contact Seller" /></a>
        </section>
        <div class="clearfix"></div><!-- Just to increase height automatically -->
    </li>
<?php
endwhile;
wp_reset_query();
?>
	
</ul>
      

<div class="clearfix"></div><!-- Just to increase height automatically -->

<?php renderAdForm('left-2');?>
</section>

